//Bryan Rooney
//ISQ
//Emergency Powers and the Heterogeneity of Terror


cd "/Users/brooney/Documents/Pubs/Terror Paper"

use terror_data.dta, clear


label var declaredsoe "Declared State of Emergency"
label var soe_emp "Declared State of Emergency * Emergency Powers"
label var empowerscore3 "Emergency Power Strength"
label var lnpop "Population (Logged)"
label var lagterr "Terror Attacks in Previous Year"
label var gdpcap "GDP Per Capita"
label var gy1 "Economic Growth"
label var polconiii "Political  Constraints"
label var lagmid "MID in Previous Year"
label var polity2 "Polity Score"
label var civ_lib "Civil Liberties"
label var d_3 "Political Ideology Terror Attacks (Next 3 Years)"
label var f_3 "Separatist Terror Attacks (Next 3 Years)"
label var terr_3 "Terror Attacks (Next 3 Years)"
label var is_3 "Islamic Terror Attacks (Next 3 Years)"
label var rel_ni "Other Religious Terror Attacks (Next 3 Years)"

	global X lnpop gdpcap gy1 civ_lib polconiii polity2 lagmid lagterr 


cd "/Users/brooney/Documents/Pubs/Terror Paper/ISQ/R and R/Final/Tables"

//Main
eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
estout using "Model_main.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.region i.year, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.region i.year, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.region i.year, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.year, robust
estout using "Model_yr.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.ccode i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.ccode i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.ccode i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.ccode i.decade, robust
estout using "Model_dc.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.ccode i.year, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.ccode i.year, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.ccode i.year, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.ccode i.year, robust
estout using "Model_yc.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, cluster(ccode)
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, cluster(ccode)
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, cluster(ccode)
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, cluster(ccode)
estout using "Model_cluster.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

eststo clear
eststo: nbreg d_3 declaredsoe  empowerscore3  $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe  empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe  empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe  empowerscore3  $X i.region i.decade, robust
estout using "constituent_parts.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

//Varied Time Frame

eststo clear
eststo: nbreg d_2 declaredsoe soe_emp empowerscore3 $X i.region i.decade, robust
eststo: nbreg f_2 declaredsoe soe_emp empowerscore3 $X i.region i.decade, robust
eststo: nbreg d_4 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: nbreg f_4 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
estout using "Model_time.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology 2 Years" "Separatist 2 Years" "Political Ideology 4 Years" "Separatist 4 Years", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear


eststo clear
eststo: reg ln_fatal_d2 declaredsoe soe_emp empowerscore3 $X i.region i.decade, robust
eststo: reg ln_fatal_f2 declaredsoe soe_emp empowerscore3 $X i.region i.decade, robust
eststo: reg ln_fatal_d4 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_d4 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
estout using "Model_time_f.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology 2 Years" "Separatist 2 Years" "Political Ideology 4 Years" "Separatist 4 Years", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

//INEP

gen soe_inep=guessbenefitinep*declaredsoe
gen soe_inep_cost=guesscostinep*declaredsoe

label var soe_inep "Declared State of Emergency * INEP Benefits"
label var guesscostinep "INEP Costs"
label var guessbenefitinep "INEP Benefits"

	global X lnpop gdpcap gy1 civ_lib polconiii polity2 lagmid lagterr 

	
eststo clear
eststo: nbreg d_3 declaredsoe soe_inep guessbenefitinep  $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_inep guessbenefitinep  $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_inep guessbenefitinep  $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_inep guessbenefitinep  $X i.region i.decade, robust
estout using "Model_inep.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(guessbenefitinep soe_inep declaredsoe $X  _cons) ///
		order(guessbenefitinep soe_inep declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3 guesscostinep $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3 guesscostinep $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3 guesscostinep $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3 guesscostinep $X i.region i.decade, robust
estout using "Model_inep_costs.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe guesscostinep $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe guesscostinep $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

// Lag Terror

sort ccode year
by ccode: egen terrmean=mean(lagterr)

sort ccode year
by ccode: egen terrmed=median(lagterr)

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if lagterr>terrmed & lagterr!=., robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if lagterr>terrmed & lagterr!=., robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if lagterr>terrmed & lagterr!=., robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if lagterr>terrmed & lagterr!=., robust
estout using "Model_lagterr_main.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

//IV 

gen lwords=log(wordcount)
gen lwordsne=log(otherwords)
gen lowrdsnesq=lwordsne*lwordsne
gen lwordsnefx=log(otherwordsfx)
gen lwordsnefxsq=lwordsnefx*lwordsnefx
gen int1=lwordsne*declaredsoe
gen int2=lowrdsnesq*declaredsoe
tab region, gen(rfe)
tab decade, gen(dfe)
gen int3=lwordsne*turaldisastersoe
gen int4=lowrdsnesq*turaldisastersoe
gen int5=empowerscore3*turaldisastersoe
gen int6=empowerscore3*turaldisastersoe

eststo clear
eststo:  ivpois d_3 declaredsoe gdpcap gy1 lnpop polconiii polity2 lagmid lagterr  civ_lib rfe* dfe* if extraconstitutiol!=1, endog(empowerscore3 soe_emp)  exog(lwordsne lowrdsnesq int1 int2) 
eststo:  ivpois f_3 declaredsoe gdpcap gy1 lnpop polconiii polity2 lagmid lagterr  civ_lib rfe* dfe* if extraconstitutiol!=1, endog(empowerscore3 soe_emp)  exog(lwordsne lowrdsnesq int1 int2) 
eststo:  ivreg2  ln_fatal_d3  declaredsoe gdpcap gy1 lnpop polconiii polity2 lagmid lagterr  civ_lib rfe* dfe* (empowerscore3 soe_emp = lwordsne lowrdsnesq int1 int2)  if extraconstitutiol!=1, gmm2s
eststo:  ivreg2 ln_fatal_f3 declaredsoe gdpcap gy1 lnpop polconiii polity2 lagmid lagterr  civ_lib rfe* dfe* (empowerscore3 soe_emp = lwordsne lowrdsnesq int1 int2)  if extraconstitutiol!=1, gmm2s
estout using "Model_main_iv.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear


//Civil War

label var civwar "Civil War"
label var actcivwar "Active Civil War"

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3 actcivwar $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3 actcivwar $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3 actcivwar $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3 actcivwar $X i.region i.decade, robust
estout using "Model_civwar_main.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X actcivwar _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X actcivwar _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear



//Backlash
label var anti "Vigilante Terror Violence"

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3 anti $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3 anti $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3 anti $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3 anti $X i.region i.decade, robust
estout using "Model_anti_main.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X anti _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X anti _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear



//Graphs

set scheme s1mono


eststo: nbreg f_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 )
marginsplot, xscale(range(-1.5 2)) xtitle("Emergency Powers") ytitle("Predicted Count of Separatist Terrorist Attacks") ti("States of Emergency and Terrorism") xlabel(`=-1.017921' "Min" `=0' "Mean" `=1.641703' "Max") 
graph save f1.pdf, replace

eststo: nbreg f_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=0 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 )
marginsplot, xscale(range(-1.5 2)) xtitle("Emergency Powers") ytitle("Predicted Count of Separatist Terrorist Attacks") ti("Emergency Powers and Terrorism") xlabel(`=-1.017921' "Min" `=0' "Mean" `=1.641703' "Max") 
graph save f2.pdf, replace


eststo: nbreg d_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 )
marginsplot, xscale(range(-1.5 2)) xtitle("Emergency Powers") ytitle("Predicted Count of Political Ideology Ideology Terrorist Attacks") ti("States of Emergency and Terrorism") xlabel(`=-1.017921' "Min" `=0' "Mean" `=1.641703' "Max") 
graph save d1.pdf, replace

eststo: nbreg d_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=0 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 )
marginsplot, xscale(range(-1.5 2)) xtitle("Emergency Powers") ytitle("Predicted Count of Political Ideology Ideology Terrorist Attacks") ti("Emergency Powers and Terrorism") xlabel(`=-1.017921' "Min" `=0' "Mean" `=1.641703' "Max") 
graph save d2.pdf, replace

//graph combine f1 f2 d1 d2, ycommon


eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust

margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) expression(exp(predict(xb)))
marginsplot

margins, at(empowerscore3=(.0007257 .9677334) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) expression(exp(predict(xb)))

eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust

margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 ) expression(exp(predict(xb)))
marginsplot

margins, at(empowerscore3=(.0007257 .9677334) declaredsoe=1 ) expression(exp(predict(xb)))
marginsplot

margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) 
marginsplot, xscale(range(-1.5 2)) xtitle("Emergency Powers") ytitle("Predicted Count of Political Ideology Ideology Terrorist Attacks") ti("Emergency Powers and Terrorism") xlabel(`=-1.017921' "Min" `=0' "Mean" `=1.641703' "Max") 


eststo: nbreg f_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) saving(file1, replace)

eststo: nbreg f_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=0 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) saving(file2, replace)

eststo: nbreg d_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) saving(file3, replace)

eststo: nbreg d_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=0 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) saving(file4, replace)

//combomarginsplot file1 file2 
//combomarginsplot file3 file4

//combomarginsplot file1 file3
//combomarginsplot file2 file4

//Margins


eststo: nbreg f_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) post
test _b[1._at] = _b[27._at]

eststo: nbreg f_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=0 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) post
test _b[1._at] = _b[27._at]

eststo: nbreg d_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) post
test _b[1._at] = _b[27._at]

eststo: nbreg d_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-1.017921 (.1) 1.641703) declaredsoe=0 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) post
test _b[1._at] = _b[27._at]

eststo: nbreg f_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-.4865506 1.4489162) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) post
test _b[1._at] = _b[2._at]

eststo: nbreg d_3 declaredsoe##c.empowerscore3 $X i.region i.decade, robust
margins, at(empowerscore3=(-.4865506 1.4489162) declaredsoe=1 lnpop=16.23 gdpcap=10.463 gy1=2.117 civ_lib=2.197 polconiii=0.403 polity2=8.840 lagmid=0.205 lagterr=21.67 ) post
test _b[1._at] = _b[2._at]


//Granger

//VAR
sort ccode year
quietly by ccode year: gen dup = cond(_N==1,0,_n)
	browse if dup>0
	drop if dup>0
	drop dup
	
//pvar sepeth_iden declaredsoe empowerscore3
//pvargranger

//pvar pol_iden declaredsoe empowerscore3
//pvargranger

reg declaredsoe lagterr
reg declaredsoe lagterr i.ccode i.year

gen all_terr = pol_iden + sepeth_iden + rel_iden

reg all_terr lagsoe
reg all_terr lagsoe i.ccode i.year

eststo clear
eststo: reg all_terr lagsoe
eststo: reg declaredsoe lagterr
	estout using "granger1.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups( "All Terror" "Declared SOE", pattern(1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(lagsoe lagterr  _cons) ///
		order(lagsoe lagterr  _cons) ///
		varlabels(_cons "Constant", elist(_cons)) ///
		mlabels("(1)" "(2)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

//pvar all_terr declaredsoe
//pvar all_terr empowerscore3
//pvar all_terr declaredsoe empowerscore3

//Nat Disasters


gen pol_soe=.
replace pol_soe=0 if declaredsoe==0
replace pol_soe = 1 if declaredsoe==1 & tiolpoliticalsoe==1
replace pol_soe = 1 if declaredsoe==1 & extraterritorialsoe==1

gen polsoe_emp= empowerscore3*pol_soe

label var pol_soe "Declared Political State of Emergency"
label var polsoe_emp "Declared State of Emergency * Emergency Powers"
label var turaldisastersoe "Natural Disaster State of Emergency"

eststo clear
eststo: nbreg d_3 pol_soe polsoe_emp empowerscore3 turaldisastersoe $X i.region i.decade, robust
eststo: nbreg f_3 pol_soe polsoe_emp empowerscore3 turaldisastersoe $X i.region i.decade, robust
eststo: reg ln_fatal_d3 pol_soe polsoe_emp empowerscore3 turaldisastersoe $X i.region i.decade, robust
eststo: reg ln_fatal_f3 pol_soe polsoe_emp empowerscore3 turaldisastersoe $X i.region i.decade, robust
estout using "Model_main_nd.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(pol_soe polsoe_emp empowerscore3 turaldisastersoe $X  _cons) ///
		order(pol_soe polsoe_emp empowerscore3 turaldisastersoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear


//Nonlinear Income

gen gdpcapsq=gdpcap*gdpcap
global X lnpop gdpcap gdpcapsq gy1 civ_lib polconiii polity2 lagmid lagterr 

label var gdpcapsq "GDP Per Capita (Squared)"

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
estout using "Model_main_gdp.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear


//Religious

drop _merge
sort country year
merge  country year using "/Users/brooney/Documents/Pubs/Terror Paper/islam_fatal.dta"

replace is_fatal=0 if is_fatal==. & year>=1970

sort ccode year
bysort ccode : gen isf_lp1=is_fatal[_n+1]

sort ccode year
bysort ccode : gen isf_lp2=is_fatal[_n+2]

sort ccode year
bysort ccode : gen isf_lp3=is_fatal[_n+3]

sort ccode year
bysort ccode : gen isf_lp4=is_fatal[_n+4]

gen isf_3=.
replace isf_3=isf_lp1+ isf_lp2 +isf_lp3 if isf_lp1!=. & isf_lp2!=. & isf_lp3!=.
gen ln_isf_3=asinh(isf_3)


gen islam_rel=0
replace islam_rel=1 if country=="Pakistan"
replace islam_rel=1 if country=="Malaysia"
replace islam_rel=1 if country=="Bangladesh"
replace islam_rel=1 if country=="Comoros"

eststo clear

eststo: nbreg is_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if islam_rel==0, robust
eststo: reg ln_isf_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if islam_rel==0, robust
estout using "islamic.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Islamic Terror Attacks" "Islamic Terror Fatalities", pattern(1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes \\")) ///
		mlabels("(1)" "(2)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear


//CIRI

drop _merge
sort ccode year
merge ccode year using "/Users/brooney/Documents/Pubs/Terror Paper/CIRI.dta"

label var physint "Physical Integrity Rights"
label var new_empinx "Empowerment Rights"

sort ccode year
bysort ccode : gen physint_lp1=physint[_n+1]
sort ccode year
bysort ccode : gen new_empinx_lp1=new_empinx[_n+1]
sort ccode year
bysort ccode : gen tort_1=tort[_n+1]

sort ccode year
bysort ccode : gen physintl1=physint[_n-1]
sort ccode year
bysort ccode : gen new_empinxl1=new_empinx[_n-1]

sort ccode year
bysort ccode : gen physint_ch= physint - physintl1
sort ccode year
bysort ccode : gen new_empinx_ch= new_empinx - new_empinxl1


label var physint_lp1 "Physical Integrity Rights (Subsequent Year)"
label var new_empinx_lp1 "Empowerment Rights (Subsequent Year)"

	global X lnpop gdpcap gy1 civ_lib polconiii polity2 lagmid lagterr
	
eststo clear
eststo: reg new_empinx_ch declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
estout using "Model_repression_new.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Empowerment Rights Change", pattern(1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Decade Fixed Effects & Yes \\")) ///
		mlabels("(1)" ) ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear


//DPI

drop _merge 	
sort country year
merge country year using "/Users/brooney/Documents/Pubs/Terror Paper/DPI2017_stata13.dta"
drop if constitutionyear ==.

sort country year
quietly by country year: gen dup = cond(_N==1,0,_n)
	browse if dup>0
	drop if dup>0
	drop dup

	replace execrlc = . if  execrlc==-999
		replace execrlc = . if  execrlc==0
replace gov1rlc = . if  gov1rlc==-999
replace gov1rlc = . if  gov1rlc==0


	global X lnpop gdpcap gy1  polconiii civ_lib  polity2 lagmid lagterr 
	
eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3 i.gov1rlc $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3 i.gov1rlc $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3 i.gov1rlc $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3 i.gov1rlc $X i.region i.decade, robust
estout using "Model_main_rlc.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear


	global X lnpop gdpcap gy1 gov1vote  polconiii civ_lib  polity2 lagmid lagterr 
	label var gov1vote "Major Party Vote Share"

		
eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.decade, robust
estout using "Model_main_vtshare.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear



//Pre/Post 9/11

drop _merge 	
sort ccode year
merge ccode year using "/Users/brooney/Documents/Pubs/Terror Paper/new_wb.dta"

gen post_01=.
replace post_01=1 if year>=2002 & year!=.
replace post_01=0 if year<2002 & year!=.
gen ln_gdppc= asinh(gdppc)
global X ln_pop ln_gdppc gdp_g civ_lib polconiii polity2 lagmid lagterr 

label var post_01 "Post September 11"


eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3 post_01 $X i.region i.decade, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3 post_01 $X i.region i.decade, robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3 post_01 $X i.region i.decade, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3 post_01 $X i.region i.decade, robust
estout using "Model_911_control.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X post_01 _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X post_01 _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if year<=2001 , robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if year<=2001 , robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if year<=2001, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3  $X i.region i.decade if year<=2001 , robust
estout using "Model_pre911.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region and Decade Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear

eststo clear
eststo: nbreg d_3 declaredsoe soe_emp empowerscore3  $X  if year>=2001, robust
eststo: nbreg f_3 declaredsoe soe_emp empowerscore3  $X  if year>=2001 , robust
eststo: reg ln_fatal_d3 declaredsoe soe_emp empowerscore3 $X  if year>=2001, robust
eststo: reg ln_fatal_f3 declaredsoe soe_emp empowerscore3 $X  if year>=2001 , robust
estout using "Model_post911.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		mgroups("Political Ideology Attacks" "Separatist Attacks" "Political Ideology Fatalities" "Separatist Fatalities", pattern(1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		keep(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		order(empowerscore3 soe_emp declaredsoe $X  _cons) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Region Fixed Effects & Yes & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	
eststo clear
